package com.anyou.mall.goo.goodsComment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.common.annotation.ShopScope;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.goo.goodsComment.domain.GooGoodsComment;
import com.anyou.mall.goo.goodsComment.service.IGooGoodsCommentService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 商品评价Controller
 *
 * @author ruoyi
 * @date 2022-03-25
 */
@Api(tags = "商品评价")
@RestController
@RequestMapping("/goo/goodsComment")
public class GooGoodsCommentController extends BaseController
{
    @Autowired
    private IGooGoodsCommentService gooGoodsCommentService;

    /**
     * 查询商品评价列表
     */
    @ApiOperation("查询商品评价列表")
    @PreAuthorize("@ss.hasPermi('goo:goodsComment:list')")
    @GetMapping("/list")
    @ShopScope(baseTableAlias = "a")
    public TableDataInfo<List<GooGoodsComment>> list(GooGoodsComment gooGoodsComment)
    {
        startPage();
        List<GooGoodsComment> list = gooGoodsCommentService.selectGooGoodsCommentList(gooGoodsComment);
        return getDataTable(list);
    }

    /**
     * 导出商品评价列表
     */
    @ApiOperation("导出商品评价列表")
    @PreAuthorize("@ss.hasPermi('goo:goodsComment:export')")
    @Log(title = "商品评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ShopScope(baseTableAlias = "a")
    public void export(HttpServletResponse response, GooGoodsComment gooGoodsComment)
    {
        List<GooGoodsComment> list = gooGoodsCommentService.selectGooGoodsCommentList(gooGoodsComment);
        ExcelUtil<GooGoodsComment> util = new ExcelUtil<GooGoodsComment>(GooGoodsComment.class);
        util.exportExcel(response, list, "商品评价数据");
    }

    /**
     * 获取商品评价详细信息
     */
    @ApiOperation("获取商品评价详细信息")
    @PreAuthorize("@ss.hasPermi('goo:goodsComment:query')")
    @GetMapping(value = "/{goodsCommentId}")
    public ApiResult<GooGoodsComment> getInfo(@PathVariable("goodsCommentId") Long goodsCommentId)
    {
        return ApiResult.success(gooGoodsCommentService.selectGooGoodsCommentByGoodsCommentId(goodsCommentId));
    }

    /**
     * 新增商品评价
     */
    @ApiOperation("新增商品评价")
    @PreAuthorize("@ss.hasPermi('goo:goodsComment:add')")
    @Log(title = "商品评价", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody GooGoodsComment gooGoodsComment)
    {
        return ApiResult.success(gooGoodsCommentService.insertGooGoodsComment(gooGoodsComment));
    }

    /**
     * 修改商品评价
     */
    @ApiOperation("修改商品评价")
    @PreAuthorize("@ss.hasPermi('goo:goodsComment:edit')")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody GooGoodsComment gooGoodsComment)
    {
        return ApiResult.success(gooGoodsCommentService.updateGooGoodsComment(gooGoodsComment));
    }

    /**
     * 删除商品评价
     */
    @ApiOperation("删除商品评价")
    @PreAuthorize("@ss.hasPermi('goo:goodsComment:remove')")
    @Log(title = "商品评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{goodsCommentIds}")
    public ApiResult remove(@PathVariable Long[] goodsCommentIds)
    {
        return ApiResult.success(gooGoodsCommentService.deleteGooGoodsCommentByGoodsCommentIds(goodsCommentIds));
    }

    /**
     * 商家回复用户评价
     */
    @ApiOperation("商家回复用户评价")
    @PreAuthorize("@ss.hasPermi('goo:goodsComment:replyContent')")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping("/replyContent")
    @ApiImplicitParams({
            @ApiImplicitParam(name="goodsCommentId",dataType="Long",required=true,value="评论编号"),
            @ApiImplicitParam(name="replyContent",dataType="String",required=false,value="回复内容"),
    })
    public ApiResult replyContent(@RequestParam("goodsCommentId")Long goodsCommentId,@RequestParam("replyContent")String replyContent)
    {
        return ApiResult.success(gooGoodsCommentService.replyContent(goodsCommentId,replyContent));
    }

    /**
     * 修改商品评价
     */
    @ApiOperation("商家回复用户追评价")
    @PreAuthorize("@ss.hasPermi('goo:goodsComment:replyContent')")
    @Log(title = "商品评价", businessType = BusinessType.UPDATE)
    @PutMapping("/replyContentAdd")
    @ApiImplicitParams({
            @ApiImplicitParam(name="goodsCommentAddId",dataType="Long",required=true,value="追评编号"),
            @ApiImplicitParam(name="replyContent",dataType="String",required=false,value="回复内容"),
    })
    public ApiResult replyContentAdd(@RequestParam("goodsCommentAddId")Long goodsCommentAddId,@RequestParam("replyContent")String replyContent)
    {
        return ApiResult.success(gooGoodsCommentService.replyContentAdd(goodsCommentAddId,replyContent));
    }
}
